<template>
  <view class="balance-detail-page">
    <image class="page-bg" src="/static/images/bg.png" mode="aspectFill" />
    <view class="gradient-bg" :style="{ top: navBarHeight + 'px' }"></view>
    <CustomNavbar title="充值记录" />
    
    <view class="page-content" :style="{ paddingTop: navBarHeight + 'px' }">
      <view class="user-info-section">
        <view class="user-phone">
          <text class="phone-number">{{ phoneNumber }}</text>
          <view class="date-picker" @click="showDatePicker">
            <image class="calendar-icon" src="/static/icons/icon-data.png" mode="aspectFit" />
            <text class="date-text">{{ currentDate }}</text>
          </view>
        </view>
        
        <!-- <scroll-view class="month-scroll" scroll-x> -->
          <view class="month-tabs">
            <view 
              class="tab-item" 
              v-for="(month, index) in monthTabs" 
              :key="index"
              :class="{ active: currentMonth === index }"
              @click="switchMonth(month, index)"
            >
              {{ month }}
            </view>
          </view>
        <!-- </scroll-view> -->
      </view>
      <!-- 变动明细 -->
      <view class="detail-section">
        <view class="section-header">
          <view class="section-line"></view>
          <text class="section-title">充值记录明细</text>
        </view>
        <view class="detail-list">
          <view 
            class="detail-item" 
            v-for="(item, index) in detailList" 
            :key="index"
          >
            <!-- 顶部：入账金额和金额 -->
            <view class="item-header">
              <text class="amount-label">入账金额</text>
              <text class="item-amount">{{ item.amount }}元</text>
            </view>
            
            <!-- 日期时间 -->
            <text class="item-time">{{ item.time }}</text>
            
            <!-- 详情信息 -->
            <view class="item-details">
              <view class="detail-row">
                <text class="detail-label">缴费渠道</text>
                <text class="detail-value">{{ item.paymentChannel }}</text>
              </view>
              <view class="detail-row">
                <text class="detail-label">缴费方式</text>
                <text class="detail-value">{{ item.paymentMethod }}</text>
              </view>
              <view class="detail-row">
                <text class="detail-label">使用范围</text>
                <text class="detail-value">{{ item.usageScope }}</text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import CustomNavbar from '@/components/CustomNavbar.vue'
import { api } from '@/utils/api'

const navBarHeight = ref(88)
const phoneNumber = ref('189*****0691')
const currentDate = ref((new Date().getMonth() + 1) + '月'+(new Date().getDate())+'日')
const currentMonth = ref(0)
const monthTabs = ref(['9月', '8月', '7月', '6月', '5月', '4月', '3月'])
const paymentAmount = ref('0.00')
const expenseAmount = ref('108.60')

const detailList = ref([
  {
    amount: '100',
    time: '2025-09-12 12:32:11',
    paymentChannel: '银行',
    paymentMethod: '现金',
    usageScope: '通用余额'
  },
  {
    amount: '100',
    time: '2025-09-12 12:32:11',
    paymentChannel: '银行',
    paymentMethod: '现金',
    usageScope: '通用余额'
  },
  {
    amount: '0',
    time: '2025-09-12 12:32:11',
    paymentChannel: '第三方支付',
    paymentMethod: '现金',
    usageScope: '通用余额'
  }
])

onMounted(() => {
  const windowInfo = uni.getWindowInfo()
  const statusBarHeight = windowInfo.statusBarHeight || 0
  navBarHeight.value = statusBarHeight + 44

  getData(monthTabs.value[currentMonth.value].replace('月', ''))
})

const getData = async (month) => {
  api.getRechargeRecord({
    billingCycle:month,
    wxtype:'xcx'
  }).then(res => {
    const data = res.data.list || []
    
    detailList.value = []
    data.forEach(item => {
      let items = {}
      items.amount = item.paymentAmount
      items.time = item.stateDate
      items.paymentChannel = item.payChannelId
      items.paymentMethod = item.paymentMethod
      items.usageScope = item.balanceTypeFlag
      detailList.value.push(items)
    })
    console.log('detailList = ', JSON.stringify(detailList.value))
  }).catch(err => {
    console.error('查询失败:', err)
  })
}

const showDatePicker = () => {
  // 显示日期选择器
  uni.showToast({
    title: '日期选择功能',
    icon: 'none'
  })
}
const switchMonth = (month, index) => {
  currentMonth.value = index
  console.log('切换月份:', month)
  // 这里可以添加获取对应月份数据的逻辑
  getData(month.replace('月', ''))
}
</script>

<style scoped>
.balance-detail-page {
   
  position: relative;
  z-index: 1;
}

.page-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  object-fit: cover;
}

.gradient-bg {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  pointer-events: none;
  /* background: linear-gradient(180deg, rgba(78, 138, 254, 0.8) 0%, rgba(78, 138, 254, 1) 100%); */
}

.page-content {
  position: relative;
  z-index: 2;
  padding: 40rpx;
  padding-bottom: 40rpx;
}

/* 用户信息区域 */
.user-info-section {
  /* padding: 40rpx 32rpx 0 32rpx; */
  margin-top: 40rpx;
}

.user-phone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40rpx;
}

.phone-number {
  color: rgba(255, 255, 255, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 32rpx;
  font-weight: 700;
  line-height: 38rpx;
}

.date-picker {
  display: flex;
  align-items: center;
  border-radius: 40px;
backdrop-filter: blur(8px);
background: linear-gradient(180.00deg, rgba(255, 255, 255, 0.9),rgba(222.26136779785156, 233.55055236816406, 255, 0.9) 20%,rgba(197, 217, 255, 0.9) 53%,rgba(227.102294921875, 236.72218322753906, 255, 0.9) 90%,rgba(255, 255, 255, 0.9) 100%);
  gap: 8rpx;
  padding: 8rpx 16rpx;
}

.calendar-icon {
  width: 32rpx;
  height: 32rpx;
}

.date-text {
  color: rgba(78, 138, 254, 1);
font-family: HarmonyOS Sans SC;
font-size: 28rpx;
font-weight: 500;
line-height: 32rpx;
}

/* 月份标签 */
.month-scroll {
  margin-bottom: 30rpx;
  white-space: nowrap;
}

/* .month-tabs {
  display: flex;
  gap: 16rpx;
  padding: 0 4rpx;
  white-space: nowrap;
} */
.month-tabs {
  display: flex;
  justify-content: space-around;
  text-align: center;
  align-items: center;
  margin-bottom: 30rpx;
  overflow-x: auto;
}

.tab-item {
  padding: 8rpx 16rpx;
  color: rgba(255, 255, 255, 0.8);
  font-family: HarmonyOS Sans SC;
  font-size: 32rpx;
  font-weight: 400;
  line-height: 38rpx;
  border-radius: 8rpx;
  white-space: nowrap;
}

.tab-item.active {
  border-radius: 20px;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 1);
  color: rgba(78, 138, 254, 1);
}

/* 摘要卡片 */

.summary-cards {
  display: flex;
  align-items: center;
  /* justify-content: space-between; */
  flex-direction: column;
  z-index: 2;
  margin-bottom: 32rpx;
}
.bg-image {
   width: 670rpx;
  height: 158rpx;
}
.summary-cards-wrapper{
 position: absolute; 
 display: flex;
 align-items: center;
  justify-content: space-between;
}
.summary-card {
  border-radius: 16rpx;
  padding: 32rpx 100rpx;
  flex-direction: column;
  display: flex;
  /* justify-content: space-between; */
  align-items: center;
}


.card-title {
  color: rgba(255, 255, 255, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 28rpx;
  font-weight: 400;
  line-height: 32rpx;
  margin-bottom: 16rpx;
}

.card-value {
  color: rgba(255, 255, 255, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 48rpx;
  font-weight: 700;
  line-height: 56rpx;
}

/* 变动明细 */
.detail-section {
  margin-bottom: 40rpx;
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 24rpx;
}

.section-line {
  width: 8rpx;
  height: 40rpx;
  background: rgba(78, 138, 254, 1);
  border-radius: 4rpx;
  margin-right: 16rpx;
}

.section-title {
  color: rgba(255, 255, 255, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 32rpx;
  font-weight: 700;
  line-height: 38rpx;
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.detail-item {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 8rpx 8rpx 0px rgba(125, 182, 251, 0.1);
  border-radius: 16rpx;
  padding: 24rpx;
  display: flex;
  flex-direction: column;
  margin-bottom: 16rpx;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12rpx;  
  background: rgba(255, 255, 255, 1);
}

.amount-label {
  color: rgba(51, 51, 51, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 28rpx;
  font-weight: 400;
  line-height: 32rpx;
}

.item-amount {
  color: rgba(78, 138, 254, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 32rpx;
  font-weight: 500;
  line-height: 38rpx;
}

.item-time {
  color: rgba(153, 153, 153, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 24rpx;
  font-weight: 400;
  line-height: 28rpx;
  margin-bottom: 16rpx;
}

.item-details {
  background: rgba(247, 247, 247, 1);
  border-radius: 0px 0px 16rpx 16rpx;
box-shadow: 0px 4px 4px 0px rgba(125, 182, 251, 0.1),inset 0px 3px 5px 0px rgba(0, 0, 0, 0.05);
  padding: 24rpx;
  margin: 16rpx -24rpx -24rpx -24rpx;
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-label {
  color: rgba(153, 153, 153, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 28rpx;
  font-weight: 400;
  line-height: 32rpx;
}

.detail-value {
  color: rgba(102, 102, 102, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 28rpx;
  font-weight: 400;
  line-height: 32rpx;
}

/* 温馨提示 */
.tips-section {
  margin-bottom: 40rpx;
}

.tips-content {
  padding: 0;
}

.tips-text {
  color: rgba(102, 102, 102, 1);
  font-family: HarmonyOS Sans SC;
  font-size: 24rpx;
  font-weight: 400;
  line-height: 36rpx;
}
</style>
